package com.oddfar.campus.business.controller;

import com.oddfar.campus.business.domain.Tcwxx;
import com.oddfar.campus.business.domain.Tcwxx;
import com.oddfar.campus.business.mapper.TcwxxMapper;
import com.oddfar.campus.business.service.TcwxxService;
import com.oddfar.campus.common.domain.PageResult;
import com.oddfar.campus.common.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fjdcgl/tcwxx")
public class TcwxxController {
    
    @Autowired
    private TcwxxService tcwxxService;
    
    @Autowired
    private TcwxxMapper tcwxxMapper;
    
    @RequestMapping(value = "/list", name = "查询车位列表")
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    public R list(Tcwxx tcwxx) {
        PageResult<Tcwxx> page = tcwxxService.page(tcwxx);
        return R.ok().put(page);
    }

    /**
     * 获取车辆详细信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @GetMapping(value = "/{tcwid}", name = "获取车位详细信息")
    public R getInfo(@PathVariable("tcwid") Long mobile) {
        return R.ok(tcwxxMapper.selectById(mobile));
    }

    /**
     * 新增车位信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @PostMapping(name = "新增车位信息")
    public R add(@RequestBody Tcwxx tcwxx) {
        return R.ok(tcwxxService.insertTcwxx(tcwxx));
    }

    /**
     * 修改车位信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @PutMapping(name = "修改车位信息")
    public R edit(@RequestBody Tcwxx tcwxx) {
        return R.ok(tcwxxService.updateTcwxx(tcwxx));
    }

    /**
     * 删除车位信息
     */
    @PreAuthorize("@ss.hasAnyRoles('common,admin,user')")
    @DeleteMapping(value = "/{tcwid}", name = "删除车位信息")
    public R remove(@PathVariable Long tcwid) {
        return R.ok(tcwxxMapper.deleteTcwxx(tcwid));
    }


}
